package com.xizi.lotterySystem.common.config;

import com.xizi.lotterySystem.common.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/**/*.html")
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/**/*.js")
                .excludePathPatterns("/**/*.png")
                .excludePathPatterns("/**/*.jpg")
                .excludePathPatterns("/**/*.ico")
                .excludePathPatterns("/**/*.svg")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/verification-code/send")
                .excludePathPatterns("/user/password/login")
                .excludePathPatterns("/user/message/login")
                .excludePathPatterns("/picture/pictureUpload")
                .excludePathPatterns("/draw/winning-records/show")
        ;
    }
}
